package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.CustomerEvaluation;
import com.realtyManage.springboot.Model.Do.Exchange;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 客户评论
 *
 * @author 杭州素色网络科技有限公司
 * @since 2019-12-31
 */

@Repository
public interface CustomerEvaluationRepository extends JpaRepository<CustomerEvaluation, Long>, JpaSpecificationExecutor<CustomerEvaluation> {

    @Query(value = "SELECT label,SUM(num) num FROM `customer_evaluation` WHERE reception_id = ?1 GROUP BY label",nativeQuery = true)
    List<String> getCountLabel(Integer uid);

    @Query(value = "SELECT COUNT(DISTINCT customer_id) num FROM `customer_evaluation` WHERE reception_id = ?1  AND `status` = 1",nativeQuery = true)
    int getCountFabulous(Integer uid);

    @Modifying
    @Transactional
    @Query(value = "delete from customer_evaluation where customer_id = ?1 and label = ?2",nativeQuery = true)
    int deleteCustomerEvaluation(Integer customerId,String label);

    @Query(value = "SELECT COUNT(1) FROM `customer_evaluation` WHERE customer_id = ?1 AND `status` = 0",nativeQuery = true)
    int sx(Integer cid);

    @Query(value = "SELECT DISTINCT(label) FROM `customer_evaluation` WHERE reception_id = ?1 AND customer_id = ?2",nativeQuery = true)
    List<String> getXz(String rid,Integer cid);

    @Modifying
    @Transactional
    @Query(value = "delete from customer_evaluation where label = ?1 and reception_id = ?2",nativeQuery = true)
    int deleteCustomerEvaluationE(String label, Integer uid);

}
